> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-wb_mcp_and_llms_rewrite.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK Reference

> Complete API reference for the Weave Python SDK

# API Overview

## Classes[​](/reference/python-sdk/weave/#classes)

* [`obj.Object`](/reference/python-sdk/weave/#class-object)

* [`dataset.Dataset`](/reference/python-sdk/weave/#class-dataset): Dataset object with easy saving and automatic versioning

* [`model.Model`](/reference/python-sdk/weave/#class-model): Intended to capture a combination of code and data the operates on an input.

* [`prompt.Prompt`](/reference/python-sdk/weave/#class-prompt)

* [`prompt.StringPrompt`](/reference/python-sdk/weave/#class-stringprompt)

* [`prompt.MessagesPrompt`](/reference/python-sdk/weave/#class-messagesprompt)

* [`eval.Evaluation`](/reference/python-sdk/weave/#class-evaluation): Sets up an evaluation which includes a set of scorers and a dataset.

* [`eval_imperative.EvaluationLogger`](/reference/python-sdk/weave/#class-evaluationlogger): This class provides an imperative interface for logging evaluations.

* [`scorer.Scorer`](/reference/python-sdk/weave/#class-scorer)

* [`annotation_spec.AnnotationSpec`](/reference/python-sdk/weave/#class-annotationspec)

* [`file.File`](/reference/python-sdk/weave/#class-file): A class representing a file with path, mimetype, and size information.

* [`markdown.Markdown`](/reference/python-sdk/weave/#class-markdown): A Markdown renderable.

* [`monitor.Monitor`](/reference/python-sdk/weave/#class-monitor): Sets up a monitor to score incoming calls automatically.

* [`saved_view.SavedView`](/reference/python-sdk/weave/#class-savedview): A fluent-style class for working with SavedView objects.

* [`audio.Audio`](/reference/python-sdk/weave/#class-audio): A class representing audio data in a supported format (wav or mp3).

## Functions[​](/reference/python-sdk/weave/#functions)

* [`api.init`](/reference/python-sdk/weave/#function-init): Initialize weave tracking, logging to a wandb project.

* [`api.publish`](/reference/python-sdk/weave/#function-publish): Save and version a python object.

* [`api.ref`](/reference/python-sdk/weave/#function-ref): Construct a Ref to a Weave object.

* [`api.get`](/reference/python-sdk/weave/#function-get): A convenience function for getting an object from a URI.

* [`call_context.require_current_call`](/reference/python-sdk/weave/#function-require_current_call): Get the Call object for the currently executing Op, within that Op.

* [`call_context.get_current_call`](/reference/python-sdk/weave/#function-get_current_call): Get the Call object for the currently executing Op, within that Op.

* [`api.finish`](/reference/python-sdk/weave/#function-finish): Stops logging to weave.

* [`op.op`](/reference/python-sdk/weave/#function-op): A decorator to weave op-ify a function or method. Works for both sync and async.

* [`api.attributes`](/reference/python-sdk/weave/#function-attributes): Context manager for setting attributes on a call.

[](https://github.com/wandb/weave/blob/master/weave/trace/api.py#L37)

### function `init`[​](/reference/python-sdk/weave/#function-init)

```
init( project_name: 'str', settings: 'UserSettings | dict[str, Any] | None' = None, autopatch_settings: 'AutopatchSettings | None' = None, global_postprocess_inputs: 'PostprocessInputsFunc | None' = None, global_postprocess_output: 'PostprocessOutputFunc | None' = None, global_attributes: 'dict[str, Any] | None' = None) → WeaveClient
```

Initialize weave tracking, logging to a wandb project.

Logging is initialized globally, so you do not need to keep a reference to the return value of init.

Following init, calls of weave.op() decorated functions will be logged to the specified project.

**Args:**

* `project_name`\*\*: The name of the Weights & Biases project to log to.

* **`settings`**: Configuration for the Weave client generally.

* **`autopatch_settings`**: Configuration for autopatch integrations, e.g. openai

* **`global_postprocess_inputs`**: A function that will be applied to all inputs of all ops.

* **`global_postprocess_output`**: A function that will be applied to all outputs of all ops.

* **`global_attributes`**: A dictionary of attributes that will be applied to all traces.

NOTE: Global postprocessing settings are applied to all ops after each op's own postprocessing. The order is always: 1. Op-specific postprocessing 2. Global postprocessing

**Returns:**
A Weave client.

[](https://github.com/wandb/weave/blob/master/weave/trace/api.py#L116)

### function `publish`[​](/reference/python-sdk/weave/#function-publish)

```
publish(obj: 'Any', name: 'str | None' = None) → ObjectRef
```

Save and version a python object.

If an object with name already exists, and the content hash of obj does not match the latest version of that object, a new version will be created.

TODO: Need to document how name works with this change.

**Args:**

* `obj`\*\*: The object to save and version.

* **`name`**: The name to save the object under.

**Returns:**
A weave Ref to the saved object.

[](https://github.com/wandb/weave/blob/master/weave/trace/api.py#L170)

### function `ref`[​](/reference/python-sdk/weave/#function-ref)

```
ref(location: 'str') → ObjectRef
```

Construct a Ref to a Weave object.

TODO: what happens if obj does not exist

**Args:**

* `location`\*\*: A fully-qualified weave ref URI, or if weave.init() has been called, "name:version" or just "name" ("latest" will be used for version in this case).

**Returns:**
A weave Ref to the object.

[](https://github.com/wandb/weave/blob/master/weave/trace/api.py#L201)

### function `get`[​](/reference/python-sdk/weave/#function-get)

```
get(uri: 'str | ObjectRef') → Any
```

A convenience function for getting an object from a URI.

Many objects logged by Weave are automatically registered with the Weave server. This function allows you to retrieve those objects by their URI.

**Args:**

* `uri`\*\*: A fully-qualified weave ref URI.

**Returns:**
The object.

**Example:**

```
weave.init("weave_get_example")dataset = weave.Dataset(rows=[{"a": 1, "b": 2}])ref = weave.publish(dataset)dataset2 = weave.get(ref) # same as dataset!
```

[](https://github.com/wandb/weave/blob/master/weave/trace/context/call_context.py#L65)

### function `require_current_call`[​](/reference/python-sdk/weave/#function-require_current_call)

```
require_current_call() → Call
```

Get the Call object for the currently executing Op, within that Op.

This allows you to access attributes of the Call such as its id or feedback while it is running.

```
@weave.opdef hello(name: str) -> None: print(f"Hello {name}!") current_call = weave.require_current_call() print(current_call.id)
```

It is also possible to access a Call after the Op has returned.

If you have the Call's id, perhaps from the UI, you can use the `get_call` method on the `WeaveClient` returned from `weave.init` to retrieve the Call object.

```
client = weave.init("
")mycall = client.get_call("")
```

Alternately, after defining your Op you can use its `call` method. For example:

```
@weave.opdef add(a: int, b: int) -> int: return a + bresult, call = add.call(1, 2)print(call.id)
```

**Returns:**
The Call object for the currently executing Op

**Raises:**

* `NoCurrentCallError`\*\*: If tracking has not been initialized or this method is invoked outside an Op.

[](https://github.com/wandb/weave/blob/master/weave/trace/context/call_context.py#L114)

### function `get_current_call`[​](/reference/python-sdk/weave/#function-get_current_call)

```
get_current_call() → Call | None
```

Get the Call object for the currently executing Op, within that Op.

**Returns:**
The Call object for the currently executing Op, or None if tracking has not been initialized or this method is invoked outside an Op.

[](https://github.com/wandb/weave/blob/master/weave/trace/api.py#L264)

### function `finish`[​](/reference/python-sdk/weave/#function-finish)

```
finish() → None
```

Stops logging to weave.

Following finish, calls of weave.op() decorated functions will no longer be logged. You will need to run weave.init() again to resume logging.

[](https://github.com/wandb/weave/blob/master/weave/trace/op.py#L1191)

### function `op`[​](/reference/python-sdk/weave/#function-op)

```
op( func: 'Callable[P, R] | None' = None, name: 'str | None' = None, call_display_name: 'str | CallDisplayNameFunc | None' = None, postprocess_inputs: 'PostprocessInputsFunc | None' = None, postprocess_output: 'PostprocessOutputFunc | None' = None, tracing_sample_rate: 'float' = 1.0, enable_code_capture: 'bool' = True, accumulator: 'Callable[[Any | None, Any], Any] | None' = None) → Callable[[Callable[P, R]], Op[P, R]] | Op[P, R]
```

A decorator to weave op-ify a function or method. Works for both sync and async. Automatically detects iterator functions and applies appropriate behavior.

[](https://github.com/wandb/weave/blob/master/../../../../../../develop/core/services/weave-python/weave-public/docs/weave/trace/api/attributes#L242)

### function `attributes`[​](/reference/python-sdk/weave/#function-attributes)

```
attributes(attributes: 'dict[str, Any]') → Iterator
```

Context manager for setting attributes on a call.

Attributes become immutable once a call begins execution. Use this
context manager to provide metadata before the call starts.

**Example:**

```
with weave.attributes({'env': 'production'}): print(my_function.call("World"))
```

[](https://github.com/wandb/weave/blob/master/weave/flow/obj.py#L42)

## class `Object`[​](/reference/python-sdk/weave/#class-object)

**Pydantic Fields:**

* `name`: `typing.Optional[str]`

* `description`: `typing.Optional[str]`

* `ref`: `typing.Optional[trace.refs.ObjectRef]`

[](https://github.com/wandb/weave/blob/master/weave/flow/obj.py#L59)

### classmethod `from_uri`[​](/reference/python-sdk/weave/#classmethod-from_uri)

```
from_uri(uri: str, objectify: bool = True) → Self
```

[](https://github.com/wandb/weave/blob/master/weave/flow/obj.py#L69)

### classmethod `handle_relocatable_object`[​](/reference/python-sdk/weave/#classmethod-handle_relocatable_object)

```
handle_relocatable_object( v: Any, handler: ValidatorFunctionWrapHandler, info: ValidationInfo) → Any
```

[](https://github.com/wandb/weave/blob/master/weave/flow/dataset.py#L23)

## class `Dataset`[​](/reference/python-sdk/weave/#class-dataset)

Dataset object with easy saving and automatic versioning

**Examples:**

```
# Create a datasetdataset = Dataset(name='grammar', rows=[ {'id': '0', 'sentence': "He no likes ice cream.", 'correction': "He doesn't like ice cream."}, {'id': '1', 'sentence': "She goed to the store.", 'correction': "She went to the store."}, {'id': '2', 'sentence': "They plays video games all day.", 'correction': "They play video games all day."}])# Publish the datasetweave.publish(dataset)# Retrieve the datasetdataset_ref = weave.ref('grammar').get()# Access a specific exampleexample_label = dataset_ref.rows[2]['sentence']
```

**Pydantic Fields:**

* `name`: `typing.Optional[str]`

* `description`: `typing.Optional[str]`

* `ref`: `typing.Optional[trace.refs.ObjectRef]`

* `rows`: `typing.Union[trace.table.Table, trace.vals.WeaveTable]`

[](https://github.com/wandb/weave/blob/master/weave/flow/dataset.py#L78)

### method `add_rows`[​](/reference/python-sdk/weave/#method-add_rows)

```
add_rows(rows: Iterable[dict]) → Dataset
```

Create a new dataset version by appending rows to the existing dataset.

This is useful for adding examples to large datasets without having to load the entire dataset into memory.

**Args:**

* `rows`\*\*: The rows to add to the dataset.

**Returns:**
The updated dataset.

[](https://github.com/wandb/weave/blob/master/weave/flow/dataset.py#L120)

### classmethod `convert_to_table`[​](/reference/python-sdk/weave/#classmethod-convert_to_table)

```
convert_to_table(rows: Any) → Union[Table, WeaveTable]
```

[](https://github.com/wandb/weave/blob/master/weave/flow/dataset.py#L60)

### classmethod `from_calls`[​](/reference/python-sdk/weave/#classmethod-from_calls)

```
from_calls(calls: Iterable[Call]) → Self
```

[](https://github.com/wandb/weave/blob/master/weave/flow/dataset.py#L51)

### classmethod `from_obj`[​](/reference/python-sdk/weave/#classmethod-from_obj)

```
from_obj(obj: WeaveObject) → Self
```

[](https://github.com/wandb/weave/blob/master/weave/flow/dataset.py#L65)

### classmethod `from_pandas`[​](/reference/python-sdk/weave/#classmethod-from_pandas)

```
from_pandas(df: 'DataFrame') → Self
```

[](https://github.com/wandb/weave/blob/master/weave/flow/dataset.py#L167)

### method `select`[​](/reference/python-sdk/weave/#method-select)

```
select(indices: Iterable[int]) → Self
```

Select rows from the dataset based on the provided indices.

**Args:**

* `indices`\*\*: An iterable of integer indices specifying which rows to select.

**Returns:**
A new Dataset object containing only the selected rows.

[](https://github.com/wandb/weave/blob/master/weave/flow/dataset.py#L70)

### method `to_pandas`[​](/reference/python-sdk/weave/#method-to_pandas)

```
to_pandas() → DataFrame
```

[](https://github.com/wandb/weave/blob/master/weave/flow/model.py#L23)

## class `Model`[​](/reference/python-sdk/weave/#class-model)

Intended to capture a combination of code and data the operates on an input. For example it might call an LLM with a prompt to make a prediction or generate text.

When you change the attributes or the code that defines your model, these changes will be logged and the version will be updated. This ensures that you can compare the predictions across different versions of your model. Use this to iterate on prompts or to try the latest LLM and compare predictions across different settings

**Examples:**

```
class YourModel(Model): attribute1: str attribute2: int @weave.op() def predict(self, input_data: str) -> dict: # Model logic goes here prediction = self.attribute1 + ' ' + input_data return {'pred': prediction}
```

**Pydantic Fields:**

* `name`: `typing.Optional[str]`

* `description`: `typing.Optional[str]`

* `ref`: `typing.Optional[trace.refs.ObjectRef]`

[](https://github.com/wandb/weave/blob/master/weave/flow/model.py#L51)

### method `get_infer_method`[​](/reference/python-sdk/weave/#method-get_infer_method)

```
get_infer_method() → Callable
```

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L77)

## class `Prompt`[​](/reference/python-sdk/weave/#class-prompt)

**Pydantic Fields:**

* `name`: `typing.Optional[str]`

* `description`: `typing.Optional[str]`

* `ref`: `typing.Optional[trace.refs.ObjectRef]`

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L78)

### method `format`[​](/reference/python-sdk/weave/#method-format)

```
format(**kwargs: Any) → Any
```

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L82)

## class `StringPrompt`[​](/reference/python-sdk/weave/#class-stringprompt)

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L86)

### method `__init__`[​](/reference/python-sdk/weave/#method-__init__)

```
__init__(content: str)
```

**Pydantic Fields:**

* `name`: `typing.Optional[str]`

* `description`: `typing.Optional[str]`

* `ref`: `typing.Optional[trace.refs.ObjectRef]`

* `content`: \`\`

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L90)

### method `format`[​](/reference/python-sdk/weave/#method-format-1)

```
format(**kwargs: Any) → str
```

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L93)

### classmethod `from_obj`[​](/reference/python-sdk/weave/#classmethod-from_obj-1)

```
from_obj(obj: WeaveObject) → Self
```

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L102)

## class `MessagesPrompt`[​](/reference/python-sdk/weave/#class-messagesprompt)

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L106)

### method `__init__`[​](/reference/python-sdk/weave/#method-__init__-1)

```
__init__(messages: list[dict])
```

**Pydantic Fields:**

* `name`: `typing.Optional[str]`

* `description`: `typing.Optional[str]`

* `ref`: `typing.Optional[trace.refs.ObjectRef]`

* `messages`: `list[dict]`

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L119)

### method `format`[​](/reference/python-sdk/weave/#method-format-2)

```
format(**kwargs: Any) → list
```

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L110)

### method `format_message`[​](/reference/python-sdk/weave/#method-format_message)

```
format_message(message: dict, **kwargs: Any) → dict
```

[](https://github.com/wandb/weave/blob/master/weave/flow/prompt/prompt.py#L122)

### classmethod `from_obj`[​](/reference/python-sdk/weave/#classmethod-from_obj-2)

```
from_obj(obj: WeaveObject) → Self
```

[](https://github.com/wandb/weave/blob/master/weave/flow/eval.py#L56)

## class `Evaluation`[​](/reference/python-sdk/weave/#class-evaluation)

Sets up an evaluation which includes a set of scorers and a dataset.

Calling evaluation.evaluate(model) will pass in rows from a dataset into a model matching the names of the columns of the dataset to the argument names in model.predict.

Then it will call all of the scorers and save the results in weave.

If you want to preprocess the rows from the dataset you can pass in a function to preprocess\_model\_input.

**Examples:**

```
# Collect your examplesexamples = [ {"question": "What is the capital of France?", "expected": "Paris"}, {"question": "Who wrote 'To Kill a Mockingbird'?", "expected": "Harper Lee"}, {"question": "What is the square root of 64?", "expected": "8"},]# Define any custom scoring function@weave.op()def match_score1(expected: str, model_output: dict) -> dict: # Here is where you'd define the logic to score the model output return {'match': expected == model_output['generated_text']}@weave.op()def function_to_evaluate(question: str): # here's where you would add your LLM call and return the output return {'generated_text': 'Paris'}# Score your examples using scoring functionsevaluation = Evaluation( dataset=examples, scorers=[match_score1])# Start tracking the evaluationweave.init('intro-example')# Run the evaluationasyncio.run(evaluation.evaluate(function_to_evaluate))
```

**Pydantic Fields:**

* `name`: `typing.Optional[str]`

* `description`: `typing.Optional[str]`

* `ref`: `typing.Optional[trace.refs.ObjectRef]`

* `dataset`: \`\`

* `scorers`: `typing.Optional[list[typing.Annotated[typing.Union[trace.op.Op, flow.scorer.Scorer], BeforeValidator(func=)]]]`

* `preprocess_model_input`: `typing.Optional[typing.Callable[[dict], dict]]`

* `trials`: \`\`

* `evaluation_name`: `typing.Union[str, typing.Callable[[trace.weave_client.Call], str], NoneType]`

[](https://github.com/wandb/weave/blob/master/weave/trace/op.py#L237)

### method `evaluate`[​](/reference/python-sdk/weave/#method-evaluate)

```
evaluate(model: Union[Op, Model]) → dict
```

[](https://github.com/wandb/weave/blob/master/weave/flow/eval.py#L114)

### classmethod `from_obj`[​](/reference/python-sdk/weave/#classmethod-from_obj-3)

```
from_obj(obj: WeaveObject) → Self
```

[](https://github.com/wandb/weave/blob/master/weave/flow/eval.py#L195)

### method `get_eval_results`[​](/reference/python-sdk/weave/#method-get_eval_results)

```
get_eval_results(model: Union[Op, Model]) → EvaluationResults
```

[](https://github.com/wandb/weave/blob/master/weave/trace/op.py#L140)

### method `predict_and_score`[​](/reference/python-sdk/weave/#method-predict_and_score)

```
predict_and_score(model: Union[Op, Model], example: dict) → dict
```

[](https://github.com/wandb/weave/blob/master/weave/trace/op.py#L172)

### method `summarize`[​](/reference/python-sdk/weave/#method-summarize)

```
summarize(eval_table: EvaluationResults) → dict
```

[](https://github.com/wandb/weave/blob/master/weave/flow/eval_imperative.py#L306)

## class `EvaluationLogger`[​](/reference/python-sdk/weave/#class-evaluationlogger)

This class provides an imperative interface for logging evaluations.

An evaluation is started automatically when the first prediction is logged using the `log_prediction` method, and finished when the `log_summary` method is called.

Each time you log a prediction, you will get back a `ScoreLogger` object. You can use this object to log scores and metadata for that specific prediction. For more information, see the `ScoreLogger` class.

**Example:**

```
 ev = EvaluationLogger() pred = ev.log_prediction(inputs, output) pred.log_score(scorer_name, score) ev.log_summary(summary)
```

**Pydantic Fields:**

* `name`: `str | None`

* `model`: `flow.model.Model | dict | str`

* `dataset`: `flow.dataset.Dataset | list[dict] | str`

#### property ui\_url[​](/reference/python-sdk/weave/#property-ui_url)

[](https://github.com/wandb/weave/blob/master/weave/flow/eval_imperative.py#L567)

### method `finish`[​](/reference/python-sdk/weave/#method-finish)

```
finish() → None
```

Clean up the evaluation resources explicitly without logging a summary.

Ensures all prediction calls and the main evaluation call are finalized. This is automatically called if the logger is used as a context manager.

[](https://github.com/wandb/weave/blob/master/weave/flow/eval_imperative.py#L490)

### method `log_prediction`[​](/reference/python-sdk/weave/#method-log_prediction)

```
log_prediction(inputs: 'dict', output: 'Any') → ScoreLogger
```

Log a prediction to the Evaluation, and return a reference.

The reference can be used to log scores which are attached to the specific prediction instance.

[](https://github.com/wandb/weave/blob/master/weave/flow/eval_imperative.py#L521)

### method `log_summary`[​](/reference/python-sdk/weave/#method-log_summary)

```
log_summary(summary: 'dict | None' = None, auto_summarize: 'bool' = True) → None
```

Log a summary dict to the Evaluation.

This will calculate the summary, call the summarize op, and then finalize the evaluation, meaning no more predictions or scores can be logged.

[](https://github.com/wandb/weave/blob/master/weave/flow/scorer.py#L19)

## class `Scorer`[​](/reference/python-sdk/weave/#class-scorer)

**Pydantic Fields:**

* `name`: `typing.Optional[str]`

* `description`: `typing.Optional[str]`

* `ref`: `typing.Optional[trace.refs.ObjectRef]`

* `column_map`: `typing.Optional[dict[str, str]]`

[](https://github.com/wandb/weave/blob/master/weave/flow/scorer.py#L25)

### method `model_post_init`[​](/reference/python-sdk/weave/#method-model_post_init)

```
model_post_init(_Scorer__context: Any) → None
```

[](https://github.com/wandb/weave/blob/master/weave/trace/op.py#L29)

### method `score`[​](/reference/python-sdk/weave/#method-score)

```
score(output: Any, **kwargs: Any) → Any
```

[](https://github.com/wandb/weave/blob/master/weave/trace/op.py#L33)

### method `summarize`[​](/reference/python-sdk/weave/#method-summarize-1)

```
summarize(score_rows: list) → Optional[dict]
```

[](https://github.com/wandb/weave/blob/master/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L12)

## class `AnnotationSpec`[​](/reference/python-sdk/weave/#class-annotationspec)

**Pydantic Fields:**

* `name`: `typing.Optional[str]`

* `description`: `typing.Optional[str]`

* `field_schema`: `dict[str, typing.Any]`

* `unique_among_creators`: \`\`

* `op_scope`: `typing.Optional[list[str]]`

[](https://github.com/wandb/weave/blob/master/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L47)

### classmethod `preprocess_field_schema`[​](/reference/python-sdk/weave/#classmethod-preprocess_field_schema)

```
preprocess_field_schema(data: dict[str, Any]) → dict[str, Any]
```

[](https://github.com/wandb/weave/blob/master/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L92)

### classmethod `validate_field_schema`[​](/reference/python-sdk/weave/#classmethod-validate_field_schema)

```
validate_field_schema(schema: dict[str, Any]) → dict[str, Any]
```

[](https://github.com/wandb/weave/blob/master/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L103)

### method `value_is_valid`[​](/reference/python-sdk/weave/#method-value_is_valid)

```
value_is_valid(payload: Any) → bool
```

Validates a payload against this annotation spec's schema.

**Args:**

* `payload`\*\*: The data to validate against the schema

**Returns:**

* **`bool`**: True if validation succeeds, False otherwise

[](https://github.com/wandb/weave/blob/master/weave/type_handlers/File/file.py#L20)

## class `File`[​](/reference/python-sdk/weave/#class-file)

A class representing a file with path, mimetype, and size information.

[](https://github.com/wandb/weave/blob/master/weave/type_handlers/File/file.py#L23)

### method `__init__`[​](/reference/python-sdk/weave/#method-__init__-2)

```
__init__(path: 'str | Path', mimetype: 'str | None' = None)
```

Initialize a File object.

**Args:**

* `path`\*\*: Path to the file (string or pathlib.Path)

* **`mimetype`**: Optional MIME type of the file - will be inferred from extension if not provided

#### property filename[​](/reference/python-sdk/weave/#property-filename)

Get the filename of the file.

**Returns:**

* **`str`**: The name of the file without the directory path.

[](https://github.com/wandb/weave/blob/master/weave/type_handlers/File/file.py#L49)

### method `open`[​](/reference/python-sdk/weave/#method-open)

```
open() → bool
```

Open the file using the operating system's default application.

This method uses the platform-specific mechanism to open the file with the default application associated with the file's type.

**Returns:**

* `bool`\*\*: True if the file was successfully opened, False otherwise.

[](https://github.com/wandb/weave/blob/master/weave/type_handlers/File/file.py#L70)

### method `save`[​](/reference/python-sdk/weave/#method-save)

```
save(dest: 'str | Path') → None
```

Copy the file to the specified destination path.

**Args:**

* `dest`\*\*: Destination path where the file will be copied to (string or pathlib.Path) The destination path can be a file or a directory.

[](https://github.com/wandb/weave/blob/master/rich/markdown.py#L519)

## class `Markdown`[​](/reference/python-sdk/weave/#class-markdown)

A Markdown renderable.

**Args:**

* **`markup`** (str): A string containing markdown.

* **`code_theme`** (str, optional): Pygments theme for code blocks. Defaults to "monokai".

* **`justify`** (JustifyMethod, optional): Justify value for paragraphs. Defaults to None.

* **`style`** (Union\[str, Style], optional): Optional style to apply to markdown.

* **`hyperlinks`** (bool, optional): Enable hyperlinks. Defaults to `True`.

* **`inline_code_lexer`**: (str, optional): Lexer to use if inline code highlighting is enabled. Defaults to None.

* **`inline_code_theme`**: (Optional\[str], optional): Pygments theme for inline code highlighting, or None for no highlighting. Defaults to None.

[](https://github.com/wandb/weave/blob/master/rich/markdown.py#L555)

### method `__init__`[​](/reference/python-sdk/weave/#method-__init__-3)

```
__init__( markup: 'str', code_theme: 'str' = 'monokai', justify: 'Optional[JustifyMethod]' = None, style: 'Union[str, Style]' = 'none', hyperlinks: 'bool' = True, inline_code_lexer: 'Optional[str]' = None, inline_code_theme: 'Optional[str]' = None) → None
```

[](https://github.com/wandb/weave/blob/master/weave/flow/monitor.py#L14)

## class `Monitor`[​](/reference/python-sdk/weave/#class-monitor)

Sets up a monitor to score incoming calls automatically.

**Examples:**

```
import weavefrom weave.scorers import ValidJSONScorerjson_scorer = ValidJSONScorer()my_monitor = weave.Monitor( name="my-monitor", description="This is a test monitor", sampling_rate=0.5, op_names=["my_op"], query={ "$expr": { "$gt": [ { "$getField": "started_at" }, { "$literal": 1742540400 } ] } } }, scorers=[json_scorer],)my_monitor.activate()
```

**Pydantic Fields:**

* `name`: `typing.Optional[str]`

* `description`: `typing.Optional[str]`

* `ref`: `typing.Optional[trace.refs.ObjectRef]`

* `sampling_rate`: \`\`

* `scorers`: `list[flow.scorer.Scorer]`

* `op_names`: `list[str]`

* `query`: `typing.Optional[trace_server.interface.query.Query]`

* `active`: \`\`

[](https://github.com/wandb/weave/blob/master/weave/flow/monitor.py#L58)

### method `activate`[​](/reference/python-sdk/weave/#method-activate)

```
activate() → ObjectRef
```

Activates the monitor.

**Returns:**
The ref to the monitor.

[](https://github.com/wandb/weave/blob/master/weave/flow/monitor.py#L68)

### method `deactivate`[​](/reference/python-sdk/weave/#method-deactivate)

```
deactivate() → ObjectRef
```

Deactivates the monitor.

**Returns:**
The ref to the monitor.

[](https://github.com/wandb/weave/blob/master/weave/flow/monitor.py#L78)

### classmethod `from_obj`[​](/reference/python-sdk/weave/#classmethod-from_obj-4)

```
from_obj(obj: WeaveObject) → Self
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L493)

## class `SavedView`[​](/reference/python-sdk/weave/#class-savedview)

A fluent-style class for working with SavedView objects.

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L499)

### method `__init__`[​](/reference/python-sdk/weave/#method-__init__-4)

```
__init__(view_type: 'str' = 'traces', label: 'str' = 'SavedView') → None
```

#### property entity[​](/reference/python-sdk/weave/#property-entity)

#### property label[​](/reference/python-sdk/weave/#property-label)

#### property project[​](/reference/python-sdk/weave/#property-project)

#### property view\_type[​](/reference/python-sdk/weave/#property-view_type)

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L623)

### method `add_column`[​](/reference/python-sdk/weave/#method-add_column)

```
add_column(path: 'str | ObjectPath', label: 'str | None' = None) → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L632)

### method `add_columns`[​](/reference/python-sdk/weave/#method-add_columns)

```
add_columns(*columns: 'str') → SavedView
```

Convenience method for adding multiple columns to the grid.

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L524)

### method `add_filter`[​](/reference/python-sdk/weave/#method-add_filter)

```
add_filter( field: 'str', operator: 'str', value: 'Any | None' = None) → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L598)

### method `add_sort`[​](/reference/python-sdk/weave/#method-add_sort)

```
add_sort(field: 'str', direction: 'SortDirection') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L663)

### method `column_index`[​](/reference/python-sdk/weave/#method-column_index)

```
column_index(path: 'int | str | ObjectPath') → int
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L578)

### method `filter_op`[​](/reference/python-sdk/weave/#method-filter_op)

```
filter_op(op_name: 'str | None') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L847)

### method `get_calls`[​](/reference/python-sdk/weave/#method-get_calls)

```
get_calls( limit: 'int | None' = None, offset: 'int | None' = None, include_costs: 'bool' = False, include_feedback: 'bool' = False, all_columns: 'bool' = False) → CallsIter
```

Get calls matching this saved view's filters and settings.

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L905)

### method `get_known_columns`[​](/reference/python-sdk/weave/#method-get_known_columns)

```
get_known_columns(num_calls_to_query: 'int | None' = None) → list[str]
```

Get the set of columns that are known to exist.

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L915)

### method `get_table_columns`[​](/reference/python-sdk/weave/#method-get_table_columns)

```
get_table_columns() → list[TableColumn]
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L617)

### method `hide_column`[​](/reference/python-sdk/weave/#method-hide_column)

```
hide_column(col_name: 'str') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L638)

### method `insert_column`[​](/reference/python-sdk/weave/#method-insert_column)

```
insert_column( idx: 'int', path: 'str | ObjectPath', label: 'str | None' = None) → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L972)

### classmethod `load`[​](/reference/python-sdk/weave/#classmethod-load)

```
load(ref: 'str') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L741)

### method `page_size`[​](/reference/python-sdk/weave/#method-page_size)

```
page_size(page_size: 'int') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L711)

### method `pin_column_left`[​](/reference/python-sdk/weave/#method-pin_column_left)

```
pin_column_left(col_name: 'str') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L721)

### method `pin_column_right`[​](/reference/python-sdk/weave/#method-pin_column_right)

```
pin_column_right(col_name: 'str') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L683)

### method `remove_column`[​](/reference/python-sdk/weave/#method-remove_column)

```
remove_column(path: 'int | str | ObjectPath') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L702)

### method `remove_columns`[​](/reference/python-sdk/weave/#method-remove_columns)

```
remove_columns(*columns: 'str') → SavedView
```

Remove columns from the saved view.

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L547)

### method `remove_filter`[​](/reference/python-sdk/weave/#method-remove_filter)

```
remove_filter(index_or_field: 'int | str') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L562)

### method `remove_filters`[​](/reference/python-sdk/weave/#method-remove_filters)

```
remove_filters() → SavedView
```

Remove all filters from the saved view.

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L520)

### method `rename`[​](/reference/python-sdk/weave/#method-rename)

```
rename(label: 'str') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L677)

### method `rename_column`[​](/reference/python-sdk/weave/#method-rename_column)

```
rename_column(path: 'int | str | ObjectPath', label: 'str') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L832)

### method `save`[​](/reference/python-sdk/weave/#method-save-1)

```
save() → SavedView
```

Publish the saved view to the server.

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L657)

### method `set_columns`[​](/reference/python-sdk/weave/#method-set_columns)

```
set_columns(*columns: 'str') → SavedView
```

Set the columns to be displayed in the grid.

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L611)

### method `show_column`[​](/reference/python-sdk/weave/#method-show_column)

```
show_column(col_name: 'str') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L605)

### method `sort_by`[​](/reference/python-sdk/weave/#method-sort_by)

```
sort_by(field: 'str', direction: 'SortDirection') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L888)

### method `to_grid`[​](/reference/python-sdk/weave/#method-to_grid)

```
to_grid(limit: 'int | None' = None) → Grid
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L769)

### method `to_rich_table_str`[​](/reference/python-sdk/weave/#method-to_rich_table_str)

```
to_rich_table_str() → str
```

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L753)

### method `ui_url`[​](/reference/python-sdk/weave/#method-ui_url)

```
ui_url() → str | None
```

URL to show this saved view in the UI.

Note this is the "result" page with traces etc, not the URL for the view object.

[](https://github.com/wandb/weave/blob/master/weave/flow/saved_view.py#L731)

### method `unpin_column`[​](/reference/python-sdk/weave/#method-unpin_column)

```
unpin_column(col_name: 'str') → SavedView
```

[](https://github.com/wandb/weave/blob/master/weave/type_handlers/Audio/audio.py#L83)

## class `Audio`[​](/reference/python-sdk/weave/#class-audio)

A class representing audio data in a supported format (wav or mp3).

This class handles audio data storage and provides methods for loading from different sources and exporting to files.

**Attributes:**

* `format`\*\*: The audio format (currently supports 'wav' or 'mp3')

* **`data`**: The raw audio data as bytes

**Args:**

* **`data`**: The audio data (bytes or base64 encoded string)

* **`format`**: The audio format ('wav' or 'mp3')

* **`validate_base64`**: Whether to attempt base64 decoding of the input data

**Raises:**

* **`ValueError`**: If audio data is empty or format is not supported

[](https://github.com/wandb/weave/blob/master/weave/type_handlers/Audio/audio.py#L108)

### method `__init__`[​](/reference/python-sdk/weave/#method-__init__-5)

```
__init__( data: 'bytes', format: 'SUPPORTED_FORMATS_TYPE', validate_base64: 'bool' = True) → None
```

[](https://github.com/wandb/weave/blob/master/weave/type_handlers/Audio/audio.py#L176)

### method `export`[​](/reference/python-sdk/weave/#method-export)

```
export(path: 'str | bytes | Path | PathLike') → None
```

Export audio data to a file.

**Args:**

* `path`\*\*: Path where the audio file should be written

[](https://github.com/wandb/weave/blob/master/weave/type_handlers/Audio/audio.py#L123)

### classmethod `from_data`[​](/reference/python-sdk/weave/#classmethod-from_data)

```
from_data(data: 'str | bytes', format: 'str') → Audio
```

Create an Audio object from raw data and specified format.

**Args:**

* `data`\*\*: Audio data as bytes or base64 encoded string

* **`format`**: Audio format ('wav' or 'mp3')

**Returns:**

* **`Audio`**: A new Audio instance

**Raises:**

* **`ValueError`**: If format is not supported

[](https://github.com/wandb/weave/blob/master/weave/type_handlers/Audio/audio.py#L148)

### classmethod `from_path`[​](/reference/python-sdk/weave/#classmethod-from_path)

```
from_path(path: 'str | bytes | Path | PathLike') → Audio
```

Create an Audio object from a file path.

**Args:**

* `path`\*\*: Path to an audio file (must have .wav or .mp3 extension)

**Returns:**

* **`Audio`**: A new Audio instance loaded from the file

**Raises:**

* **`ValueError`**: If file doesn't exist or has unsupported extension

[Edit this page](https://github.com/wandb/weave/blob/master/docs/docs/reference/python-sdk/weave/index.mdx)Last updated on **Jul 14, 2025**
